#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
int dp1[N][N];
int dp2[N];
int v[N], w[N];
int n, m;
int main()
{
	cin >> n >> m;
	for (int i = 1; i < n + 1; i++) {
		cin >> v[i] >> w[i];
	}
	/*for (int i = 1; i < n + 1; i++) {
		for (int j = 0; j < m + 1; j++) {
			dp1[i][j] = dp1[i - 1][j];
			if (j >= v[i]) {
				dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - v[i]] + w[i]);
			}
		}
	}*/
	for (int i = 1; i <= n; i++) {
		for (int j = m; j >= v[i]; j--) {
			dp2[j] = max(dp2[j], dp2[j - v[i]] + w[i]);
		}
	}
	cout << dp2[m] << endl;
	return 0;
}